<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/partes/');?>">Ramal</a></li>
  <li class="active">Novo</li>
</ol>
	<fieldset>
	<legend>Cadastro Ramais</legend>
		<?php
			$attributes = array('class' => 'form-horizontal', 'role' => 'form', 'id' => 'form');
			
			echo form_open('ramais/salvar',$attributes); 
		
		?>
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Secretaria</label>
		<div class="col-sm-3">
			<?php 
				echo form_dropdown('secretaria',$secretaria,'0','class="form-control input-sm" id="secretaria"');
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
		<?php echo form_error('tipo_processo');?>	
		</div>	
		</div>
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Setor</label>
		<div class="col-sm-3">
			<?php 
				echo form_dropdown('setores',$setores,'0','class="form-control input-sm" id="setores"');
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
		<?php echo form_error('tipo_processo');?>	
		</div>	
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
			  <div class="checkbox">
				<label>
				  <input type="checkbox" checked="checked"> Ativar Máscara
				</label>
			  </div>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="col-sm-2 control-label">Número Ramal</label>
			<div class="col-sm-1">
				<?php 
					$data = array('name'=> 'numero_processo','id'=> 'numero_processo','value'=> @$processo->numeroprocesso,'placeholder'=> '(00) 0000-0000','class'=> 'form-control input-sm');
					echo form_input($data);
				?>
			</div>
			<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('numero_processo');?>	
			</div>	
		</div>
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Observação</label>
		<div class="col-sm-4">
		  
			<?php 
				$data = array('name'=> 'observacao','id'=> 'observacao','placeholder'=> 'Observação','class'=> 'form-control input-sm','value'=>@$processo->observacao,'rows'=>'3');
				echo form_textarea($data);
			?>
		</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
			  <div class="checkbox">
				<label>
				  <input type="checkbox" >*Ocultar ramal
				</label>
			  </div>
			</div>
		</div>
		
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
			<?php 
				$data = array('name'=>'salvar','type' => 'submit','class' => 'btn btn-default','content' =>'Salvar');
				echo form_button($data);
			?>
			<a id="cancelar" href="<?php echo base_url('index.php/processos/consulta');?>" class="btn btn-primary"></span>Cancelar</a>
			</div>
		</div>
		<?php echo form_close(); ?>
		
	</fieldset>

</div>

	<script src="<?php echo base_url('includes/js/jquery.tokeninput.js')?>"></script>
	<!--<script src="<?php echo base_url('includes/js/bootstrap-tokenfield.js')?>"></script>-->
	
	<link href="<?php echo base_url('includes/css/token-input-facebook.css') ?>" rel="stylesheet"> 
	<!--<link href="<?php echo base_url('includes/css/bootstrap-tokenfield.css') ?>" rel="stylesheet">
	<link href="<?php echo base_url('includes/css/tokenfield-typeahead.css') ?>" rel="stylesheet">-->
	
	<script language="javascript" type="text/javascript">
		$(document).ready(function(){
				$("#form").validate({
					ignore: [],
					rules: {
						dia: "required",
						tipo_processo: "required",
						numero_processo: { 
							required: true, 
							remote:'<?php echo base_url('index.php/processos/validaProcesso');?>'
						},
						autor: "required",
						assunto: "required",
						reu: "required"
					},
					messages: {
						dia: "Campo requerido",
						tipo_processo: "Campo requerido",
						numero_processo: { required: 'Campo requerido', remote: ' Processo já cadastrado!' },
						autor: "Campo requerido",
						assunto: "Campo requerido",
						reu: "Campo requerido"
					}
				});
			$("#dia").datepicker({dateFormat: "dd/mm/yy"});
			$("#numero_processo").focus();
			$('#cod_bic').attr('readonly', true);
			$('#tipo_processo').change( function(){
				if($(this).val() == 3){
					$('#cod_bic').attr('readonly', false);
				}else{
					$('#cod_bic').val('');
					$('#cod_bic').attr('readonly', true);
				}

			});
			
			$("#autor").tokenInput("<?php echo base_url('index.php/partes/consultaPartesJson');?>", {
		        	theme: "facebook",
					searchDelay:"50",
					preventDuplicates: "true"
					
			});
			
			$("#reu").tokenInput("<?php echo base_url('index.php/partes/consultaPartesJson');?>", {
		        	theme: "facebook",
					searchDelay:"50",
					preventDuplicates: "true"
					
			});
			
			$("#modalparte").click(function(){
				$("#form_parte").validate({
					rules: {
						nome_parte: "required",
						cpf_cnpj: "required"
					},
					messages: {
						nome_parte: "Campo requerido",
						cpf_cnpj: "Campo requerido"
					},
					submitHandler: function(form){
						var dados = $('#form_parte').serialize();
						$.ajax({
								type: "POST",
								url: "<?php echo base_url('index.php/partes/salvarModal');?>",
								data: dados,
								success: function( data )
								{
									alert( data );
									$('#myModal').modal('hide');
									$('#nome_parte').val('');
									$('#cargo').val('');
									$('#descricao').val('');
									$('#cpf_cnpj').val('');
								}
						});
						return false;
					}
				});
			});
			$("input[name=tipo]:radio").change(function(){
				 $('input[name=cpf_cnpj]').unmask();//Remove a mascara
				 if($(this).val()=="cpf"){//Acaso seja CPF
						$("input[name=cpf_cnpj]").mask("999.999.999-99");
						$("input[name=cpf_cnpj]").attr("placeholder","CPF");
				 } else {//Acaso seja Cnpj
						$("input[name=cpf_cnpj]").mask("99.999.999/9999-99");
						$("input[name=cpf_cnpj]").attr("placeholder","CNPJ");
				 }
			})
		});
		
			
	</script>
	</body>
</html>